var app = getApp()
import * as appConfig from "../../../app-config.js";

Page({

  data: {
    accountList: []

  },

  
  onLoad: function(options) {
    // this.accountLists();
  },

  //加载门店账号列表
  onShow: function() {
    this.setData({
      accountList:[]
    })
    this.accountLists();
  },

  accountLists: function() {
    var that = this;
    app.getMemInfo().then(res => {
      var agentId=  res.data.agentId;
      var url = "/wx_app/agent/account/list";
      var data = {
        agentId: agentId
      }
      app.request(url, data, 'GET').then(res => {
        console.log(res)
        this.accountList(res);
      })
    })
  
    
  },

  //门店账号信息转化
  accountList: function (res) {
    var list = res.data;
    var accountList=[];
    list.forEach(item => {
      accountList.push({
        id: item.id,
        name: item.name,
        number: item.phone,
        password: item.password,
      });
    })
    
    this.setData({
      accountList: accountList
    })

  },


  bindAdd() {
    wx.navigateTo({
      url: 'addAccount'
    })
  },
  bindEdit(e) {
    let name = e.currentTarget.dataset.name
    let num = e.currentTarget.dataset.num
    let password = e.currentTarget.dataset.pas
    let id = e.currentTarget.dataset.id
    console.log(name)
    wx.navigateTo({
      url: 'editAccount?name=' + name + '&num=' + num + '&password=' + password + '&id=' + id
    })
  }



})